package 富婆梦.第一阶段.第三周.练习题;

import java.util.ArrayList;

public class DotComBust {
    private GameHelper helper=new GameHelper();
    private ArrayList<DotCom> dotComsList = new ArrayList<DotCom>();
    private int numOfGuesses = 0;

    private void setUpGame(){
        DotCom one=new DotCom();
        one.setName("Peter.com");
        DotCom two=new DotCom();
        one.setName("eToys.com");
        DotCom three=new DotCom();
        one.setName("Go2.com");
        dotComsList.add(one);
        dotComsList.add(two);
        dotComsList.add(three);
        System.out.println("your goal is to sink three dot coms.");
        System.out.println("Peter.com,eToys.com,Go2.com");
        System.out.println("Try to sink them");
        for (DotCom d:dotComsList){
            //设置DotCom的位置
            ArrayList<String> newLocation = helper.placeDotCom(3);
            //拿到刚刚设置的位置
            d.setLocationCells(newLocation);
        }
    }
    private void startPlaying(){
        while (!dotComsList.isEmpty()){
            //获得玩家输入
            String userGuess = helper.getUserInput("Enter aguess");
            checkUserGuess(userGuess);
        }
        finishGame();

    }
    private void checkUserGuess(String userGuess){
        numOfGuesses++;
        String result = "miss";
        for (DotCom d:dotComsList){
            result = d.checkYourself(userGuess);
            if (result.equals("hit")){
                break;
            }
            if (result.equals("sunk")){
                dotComsList.remove(d);
                break;
            }
        }
        System.out.println(result);
    }
    private void finishGame(){
        System.out.println("All Dot Com are Dead!");
        System.out.println("it took "+numOfGuesses);
    }
}
